package cn.stacey.day13;

import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.BufferedReader;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.net.Socket;
import java.net.UnknownHostException;

public class Client2 {
	//持续发送消息

	public static void main(String[] args) {

		try {
			//host主机 
			Socket socket=new Socket("127.0.0.1",6666);
				//客户端发出消息
//			OutputStream out=socket.getOutputStream();
			DataOutputStream out=new DataOutputStream(new BufferedOutputStream(socket.getOutputStream()));
//			InputStream in=socket.getInputStream();
			//BufferedReader重点理解下面代码
			InputStream in = System.in;
			BufferedReader bf=new BufferedReader(new InputStreamReader(in, "utf-8"));
			
			while(true) {
	//			char c=(char) in.read();
				//从控制台读取输入的每一行
				String line=bf.readLine();
	//			out.write(c);
				out.writeUTF(line);
				//强刷进去
				out.flush();
				if("886".equals(line)) {
					break;
				}
			}

				//客户端接收消息
			

		} catch (UnknownHostException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
//		finally {
//			UtilsClose.closeQuitely(in);
//			UtilsClose.closeQuitely(out);
//			UtilsClose.closeQuitely(socket);
//			
//		}

	}

	
}
